import { defineStore } from "pinia";
import { apiGetDetail, apiGetArticleList ,apiAddViews,apiGetHotArticle} from "../api/modules/api.blog_articles";
import { ref } from "vue";
export const useArticleStore = defineStore('article', ()=>{
    const img = ref('')
    const title = ref('')
    const subTitle = ref('')
const getArticleList = async () => {
    const res = await apiGetArticleList();
    if (res.status === 200) {
        return {
            success: true,
            data: res.data
        };
    }
    else {
        return {
            success: false,
            data: []
        };
    }
    }
    
    const getArticleDetail = async (id) => {
        const res = await apiGetDetail(id);
        if (res.status === 200) {
            return {
                success: true,
                data: res.data
            };
        }
        else {
            return {
                success: false,
                data: {}
            };
        }
    }


    const addViews = async (id) => {
        const res = await apiAddViews(id);
        if (res.status === 200) {
            return {
                success: true,
                data: res.data
            };
        }
        else {
            return {
                success: false,
                data: {}
            };
        }
    }
    const getHotArticle = async () => {
        const res = await apiGetHotArticle();
        if (res.status === 200) {
            return {
                success: true,
                data: res.data
            };
        }
        else {
            return {
                success: false,
                data: []
            };
        }
    }
    return { getArticleList, getArticleDetail ,img,title,subTitle,addViews,getHotArticle}

})
